package com.wei.test.Aspect;

import com.wei.test.Annotation.TestAnnotation;
import com.wei.test.Service.LogService;
import com.wei.test.Util.AppUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class testAspect {
    @Autowired
    LogService logService;

    @Autowired
    AppUtil appUtil;

    @Pointcut("@annotation(com.wei.test.Annotation.TestAnnotation)")
    public void annotationPointcut() {
    }

    @Around("annotationPointcut()")
    public Object afterPointcut(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = null;
        logService.info("before pointCut");
        TestAnnotation annotation = (TestAnnotation) appUtil.getAnnotationClass(TestAnnotation.class, joinPoint);
        String value = annotation.value();
        result = joinPoint.proceed();
        logService.info("after pointCut");
        return result;
    }
}
